/**
 *
 */
package com.yangtao.framework.util;

import freemarker.template.utility.StringUtil;

/**
 * 字符串处理帮助类
 *
 * @author 杨涛
 * @version 1.0
 * @date 2010-04-02
 */
public class StringHelper extends StringUtil {

	public static boolean isEmpty(String str) {
		if (str == null || str.equals(""))
			return true;
		return false;
	}

	public static boolean isNotEmpty(String str) {
		return !isEmpty(str);
	}

	/**
	 * 重写split方法，返回指定index的字符串
	 *
	 * @param str
	 * @param regx
	 * @param index
	 * @return
	 */
	public static String split(String str, String regx, int index) {
		if (str == null || regx == null) {
			return null;
		}
		int splitIndex = 0;
		int counter = 0;
		int beginIndex = 0;
		while ((splitIndex = str.indexOf(regx, splitIndex)) != -1) {
			counter++;
			if (counter + 1 == index) {
				beginIndex = splitIndex;
			}
			if (counter == index) {
				return str.substring(beginIndex + 1, splitIndex);
			}
			splitIndex++;
		}
		return null;
	}
}
